package com.example.jack.community.view.home.homeAdapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.example.jack.community.R;
import com.example.jack.community.data.HomeRcViewpagerBean;

import java.util.ArrayList;

/**
 * Created by ${justin} on 2017/10/2516: 46
 * WeChat:Justin-Tz
 * 首页viewpager的适配器
 */

public class HomeViewPagerAdapter extends RecyclerView.Adapter<HomeViewPagerAdapter.HomeViewHolder> {

    private ArrayList<HomeRcViewpagerBean> mList;
    private LayoutInflater mInflater;
    private Context mContext;


    public HomeViewPagerAdapter(Context context, ArrayList<HomeRcViewpagerBean> mList) {
        this.mContext = context;
        mInflater = LayoutInflater.from(context);
        this.mList = mList;
    }

    @Override
    public HomeViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.home_viewpager_item, parent, false);
        HomeViewHolder holder = new HomeViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(HomeViewHolder holder, int position) {
        Glide.with(mContext).load(mList.get(position % mList.size())
                .getImageUrl())
                .into(holder.ivImage);
    }

    @Override
    public int getItemCount() {
        return Integer.MAX_VALUE;
    }


    public class HomeViewHolder extends RecyclerView.ViewHolder {

        public ImageView ivImage;


        public HomeViewHolder(View itemView) {
            super(itemView);
            ivImage = (ImageView) itemView.findViewById(R.id.adapter_iv_icon);

        }
    }
}
